#define _CRT_SECURE_NO_WARNINGS 1
#include<stdlib.h>
int com_stone(const void* s1, const void* s2)
{
	return *((int*)s2) - *((int*)s1);
}
int lastStoneWeight(int* stones, int stonesSize) {
	if (stonesSize == 1)
		return *stones;
	else
	{
		int* del = stones;
		while (*(del + 1) != 0)
		{
			qsort(stones, stonesSize, sizeof(int), com_stone);
			*del <= *(del + 1) ? (*(del + 1) = *(del + 1) - *del) : (*(del + 1) = *del - *(del + 1));
			*del = 0;
			qsort(stones, stonesSize, sizeof(int), com_stone);
		}
		return *del;
	}
}